package org.ajax.servlet;

/*
 *
 *@author XCH
 *@date 2024-11-19
 *
 */

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取请求参数
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        // 模拟数据库用户验证
        String validUsername = "admin";
        String validPassword = "123";

        resp.setContentType("text/plain");
        PrintWriter out = resp.getWriter();

        if (validUsername.equals(username) && validPassword.equals(password)) {
            // 登录成功
            out.write("success");
        } else {
            // 登录失败
            out.write("fail");
        }

        out.flush();
        out.close();
    }
}
